import {Alert, Linking} from 'react-native';

export const replaceProtocol = (url = '') => {
  return url.replace(/https?\:\/\//g, '//');
};

export const replaceDouBanImg = (url = '') => {
  return `https://www.codebest.top/nextjs/douBanImg?url=${url}`;
};

export const openUrl = (url = '') => {
  console.log('openUrl', url);

  // Linking.openURL(url);
  // return;
  Linking.canOpenURL(url)
    .then(supported => {
      if (!supported) {
        Alert.alert('Cannot open URL: ' + url);
      } else {
        return Linking.openURL(url);
      }
    })
    .catch(err => console.error('An error occurred', err));
};
